# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer:
pkgname=startup
pkgver=2.0.2
pkgrel=1
pkgdesc="Event driven task and service manager"
options="!check"
url="https://gitlab.com/chinstrap/startup"
arch="all"
license="GPL-2.0-only"
makedepends="
	autoconf
	automake
	libtool
	gettext-dev
	libnih-dev
	eudev-dev
	dbus-dev
	json-c-dev
	cgmanager-dev
	linux-headers
	glib-dev
	dconf-dev
	"
checkdepends="python3 dbus"
# https://gitlab.com/chinstrap/startup/issues/42
checkdepends="$checkdepends coreutils"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-tools::noarch
	libupstart:libs
	$pkgname-bridge-udev
	$pkgname-bridge-dconf
	"
source="$pkgname-$pkgver.tar.gz::https://gitlab.com/chinstrap/startup/-/archive/$pkgver/startup-$pkgver.tar.gz"

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	export LDFLAGS="$LDFLAGS -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--sysconfdir=/etc \
		--prefix=/usr \
		--disable-sysvcompat \
		--disable-static
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	rm -rf "$pkgdir"/usr/lib/*.la
}

tools() {
	depends="$pkgname=$pkgver-r$pkgrel py3-dbus py3-gobject3"
	pkgdesc="Monitoring and analysis tools for Startup"

	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/bin/initctl2dot \
		"$pkgdir"/usr/bin/startup-monitor \
		"$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/icons \
		"$pkgdir"/usr/share/applications \
		"$subpkgdir"/usr/share
}

dconf() {
	pkgdesc="Dconf event bridge for Startup"
	install_if="$pkgname=$pkgver-r$pkgrel dconf"

	mkdir -p "$subpkgdir"/usr/libexec/startup/bridge \
		"$subpkgdir"/usr/share/startup \
		"$subpkgdir"/usr/share/xdg/startup

	mv "$pkgdir"/usr/libexec/startup/bridge/dconf \
		"$subpkgdir"/usr/libexec/startup/bridge

	# mv "$pkgdir"/usr/share/startup/bridge-dconf.conf \
	# 	"$pkgdir"/usr/share/startup/bridge-dconf.override \
	# 	"$subpkgdir"/usr/share/startup

	mv "$pkgdir"/usr/share/xdg/startup/bridge-dconf.conf \
		"$pkgdir"/usr/share/xdg/startup/bridge-dconf.override \
		"$subpkgdir"/usr/share/xdg/startup
}

udev() {
	pkgdesc="Udev event bridge for Startup"
	install_if="$pkgname=$pkgver-r$pkgrel eudev"

	mkdir -p "$subpkgdir"/usr/libexec/startup/bridge \
		"$subpkgdir"/usr/share/startup \
		"$subpkgdir"/usr/share/xdg/startup

	mv "$pkgdir"/usr/libexec/startup/bridge/udev \
		"$subpkgdir"/usr/libexec/startup/bridge

	mv "$pkgdir"/usr/share/startup/bridge-udev.conf \
		"$pkgdir"/usr/share/startup/bridge-udev.override \
		"$subpkgdir"/usr/share/startup

	mv "$pkgdir"/usr/share/xdg/startup/bridge-udev.conf \
		"$pkgdir"/usr/share/xdg/startup/bridge-udev.override \
		"$subpkgdir"/usr/share/xdg/startup
}

sha512sums="57c38f4b57f8c785971206ea94152773b2fea99919d3dbbb5e6e8f73ded4a31b3580ff6fe16ff128a424697875cf88c0e1d932b333a665e46df7c89dfa1d4093  startup-2.0.2.tar.gz"
